<?php

require 'fps.php';
require 'ball.php';

if(SDL_Init(SDL_INIT_VIDEO) == -1) {
	trigger_error(SDL_GetError());
	exit(1);
}

$screen = SDL_SetVideoMode(320, 240, 16, SDL_DOUBLEBUFF | SDL_HWSURFACE);
if(is_null($screen)) {
	trigger_error(SDL_GetError());
	exit(1);
}

$fondo = SDL_LoadBMP('images/fondo.bmp');
if(is_null($fondo)) {
	trigger_error(SDL_GetError());
	exit(1);
}

SDL_WM_SetCaption('Gravity', null);

$ball = new Ball;
$fps = new FPS(70);

$salir = false;
while(!$salir) {
	SDL_BlitSurface($fondo, null, $screen, null);
	
	$rep = $fps->update();
	for($i = 0; $i < $rep; $i++)
		$ball->update();

	$ball->draw($screen);

	SDL_Flip($screen);

	while(SDL_PollEvent(&$event)) {
		if($event['type'] == SDL_QUIT)
			$salir = 1;
		if($event['type'] == SDL_KEYDOWN)
			$salir = 1;
	}
}

unset($fps);
unset($ball);

SDL_FreeSurface($fondo);
SDL_Quit();

?>
